<?php

/**
 * Created by Reliese Model.
 * Date: Tue, 27 Aug 2019 14:14:06 +0800.
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Common\Tools\ImageUrl;

/**
 * Class Resource
 *
 * @property int $id
 * @property string $url
 * @property string $postfix
 * @property int $size
 * @property string $host_url
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 *
 * @package App\Models
 */
class Resource extends Model
{
	public $incrementing = false;

	protected $casts = [
		'id' => 'int',
		'size' => 'int'
	];

	protected $fillable = [
		'url',
		'postfix',
		'year',
		'month',
		'date',
		'user_id',
		'type',
		'size',
		'host_url'
	];

	public function data()
    {
        return $this->hasMany(Resource::class,'date','date')->where(['user_id'=>user_id()]);
    }

    public function getHostUrlAttribute($value)
    {
        return ImageUrl::img($value);
    }
}
